﻿<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link href="static/h-ui/css/H-ui.min.css" rel="stylesheet" type="text/css"/>
    <link href="static/h-ui.admin/css/H-ui.login.css" rel="stylesheet" type="text/css"/>
    <link href="static/h-ui.admin/css/style.css" rel="stylesheet" type="text/css"/>
    <link href="lib/Hui-iconfont/1.0.8/iconfont.css" rel="stylesheet" type="text/css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>后台登录 - H-ui.admin v3.0</title>
    <meta name="keywords" content="H-ui.admin v3.0,H-ui网站后台模版,后台模版下载,后台管理系统模版,HTML后台模版下载">
    <meta name="description"
          content="H-ui.admin v3.0，是一款由国人开发的轻量级扁平化网站后台模板，完全免费开源的网站后台管理系统模版，适合中小型CMS后台系统。">
</head>
<body>
<input type="hidden" id="TenantId" name="TenantId" value=""/>
<div class="header"></div>
<div class="loginWraper" id="app">

    <div id="loginform" class="loginBox">
        <h5 style="text-align: center;margin: 0px auto;padding: 0px;color:cornflowerblue;font-weight: bolder;">
            用户登录</h5>
        <form class="form form-horizontal">
            <div class="row cl">
                <label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe60d;</i></label>
                <div class="formControls col-xs-8">
                    <input id="username" v-model="loginUser.identify" name="identify" type="text" placeholder="账户"
                           class="input-text size-L">
                </div>
            </div>
            <div class="row cl">
                <label class="form-label col-xs-3"><i class="Hui-iconfont">&#xe60e;</i></label>
                <div class="formControls col-xs-8">
                    <input id="password" name="password" v-model="loginUser.password" type="password" placeholder="密码"
                           class="input-text size-L">
                </div>
            </div>
            <div class="row cl">
                <div class="formControls col-xs-8 col-xs-offset-3">
                    <input class="input-text size-L" type="text" id="randomCode" placeholder="验证码"
                           v-model="loginUser.validateCode" value="验证码:" style="width:120px;">
                    <img :src="randomCodeImgUrl" id="randomCodeImage" style="width: 120px"> <a
                        id="kanbuq"
                        href="javascript:void(0);" @click="changeRandomCodeImageUrl">看不清楚换一张</a>
                </div>
            </div>
            <div class="row cl">
                <div class="formControls col-xs-8 col-xs-offset-3">
                    <label for="online">
                        <input type="checkbox" v-model="rememberMe" name="online" id="online" value="">
                        记住我</label>
                </div>
            </div>
            <div class="row cl">
                <div class="formControls col-xs-8 col-xs-offset-3">
                    <input name="" type="button" class="btn btn-success radius size-L"
                           value="登录" @click="doLogin" >
                    <input name="" type="reset" class="btn btn-default radius size-L"
                           value="取消">
                    &nbsp;&nbsp;<a href="reg.html">立即注册</a>
                </div>
            </div>

        </form>
    </div>
</div>
<div class="footer"> &copy; 华清远见 2017-2023 &nbsp;&nbsp; 作者: 西蒙牛 v1.0</div>
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<!--此乃百度统计代码，请自行删除-->

<!--引入公共的组件库，减少屎山代码-->
<script src="js/commons/commonlibs.js"></script>
<script src="js/auth/auth.js"></script>

<script type="module">

    import {nanoid} from "./js/util/nanoid.js";
    /*
    var _hmt = _hmt || [];
    (function () {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?080836300300be57b7f34f4b3e97d911";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();*/

    let flag = await checkCurrentUserLoginStatus();
    flag = JSON.parse(flag); //字符串转换为json对象。

    if(flag){ //你已经登录了。
        window.location.href = 'index.html';
    }

    let vum = new Vue({
        el: "#app",
        data: {
            token: nanoid(32),
            randomCodeImgUrl: '',
            rememberMe: true,
            loginUser: {
                identify: '',
                password: '',
                validateCode: ''
            }
        },
        created() {

        },
        mounted() {
            //初始化用户的登录账号和密码
            if(outils.getCookie("identify.mysite.com")){
                this.loginUser.identify = decrypt(outils.getCookie("identify.mysite.com"));
                this.loginUser.password = decrypt(outils.getCookie("password.mysite.com"))
            }

            console.log("---------客户端产生的令牌--------")
            console.log(this.token);
            this.changeRandomCodeImageUrl();
        },
        methods: {

            changeRandomCodeImageUrl(){
               this.randomCodeImgUrl = baseUrl+"/commons/randomImgCode?tm="+new Date().getTime()+"&token="+this.token;
            },

            doLogin() {
                console.log("------执行用户注册--------")
                console.log(this.loginUser);


                let params = {
                    identify: this.loginUser.identify,
                    password: this.loginUser.password,
                    token : this.token,
                    code : this.loginUser.validateCode
                }
                login(params).then(resp => {
                    if (resp.data.code === 200) {
                        this.$message({
                            type: 'success',
                            message: resp.data.msg
                        })
                        sessionStorage.setItem("login.status",true);

                        //登录成功之后，咱们把登录成功的用户对象保存到localStorage
                        localStorage.setItem("loginSucessUserInfo.mysite.com",JSON.stringify(resp.data.data));

                        //检查用户是否需要'记住我'
                        if(this.rememberMe){
                            outils.setCookie("identify.mysite.com", encrypt(this.loginUser.identify));
                            outils.setCookie("password.mysite.com",encrypt(this.loginUser.password));
                        }else{
                            outils.removeCookie("identify.mysite.com");
                            outils.removeCookie("password.mysite.com");
                        }

                        setTimeout(() => {
                            window.location.href = 'index.html';
                        }, 1000)
                    } else {
                        this.$message({
                            type: 'error',
                            message: resp.data.msg
                        })
                    }

                })
            }
        }
    })

</script>
<!--/此乃百度统计代码，请自行删除
</body>
</html>